/**
 * ...
 * >author		João Vítor de Souza
 */

package com.joaosouza.core
{
	
	import com.cupcakeengine.CKEngine;
	import com.joaosouza.core.platform.IPlatformFactory;
	import com.joaosouza.core.strategy.IGameStrategy;
	import com.joaosouza.data.IGameModel;		
	import com.joaosouza.data.Screens;
	import com.joaosouza.display.IGameScreen;
	import com.joaosouza.media.IGameSound;
	import com.joaosouza.ui.IGameInput;
	import flash.display.Sprite;
	import flash.events.EventDispatcher;

	public class GameController extends EventDispatcher 
	{
		// ___________________________________________________________________ CONSTANTS
		
		// ___________________________________________________________________ CLASS PROPERTIES
		
		// ___________________________________________________________________ INSTANCE PROPERTIES
		
		private static var _instance	: GameController;				
		private var _screen				: IGameScreen;
		private var _model				: IGameModel;
		private var _input				: IGameInput;
		private var _strategy			: IGameStrategy;
		private var _sound				: IGameSound;
		
		// ___________________________________________________________________ GETTERS AND SETTERS
		
		// ___________________________________________________________________ CONSTRUCTOR
		
		public function GameController (singleton:SingletonObligate) {}
		
		// ___________________________________________________________________ PUBLIC METHODS
		
		public static function getInstance () : GameController
		{
			if (!GameController._instance) 
			GameController._instance = new GameController(new SingletonObligate());
			return GameController(GameController._instance);
		}
		
		public function init(factory:IPlatformFactory):void
		{
			_screen = CKEngine.getScreenById(Screens.GAME) as IGameScreen;								
			
			_model = _factory.getGameModel();		
			_strategy = _factory.getGameStrategy();
			_input = _factory.getGameInput();		
			_sound = _factory.getGameSound();	
			
			CKEngine.changeToScreen(Screens.GAME);
			
			initGame();
		}
		
		public function initGame():void
		{
			_input.addEvents();
		}
		
		// ___________________________________________________________________ PRIVATE METHODS
		
		// ___________________________________________________________________ EVENTS
	}
}

class SingletonObligate {}
